﻿using System.Data.Entity;
using System.Transactions;
using ElectronicGovernment.Domain.Entities;
using ElectronicGovernment.Infrastucture.EF;
using ElectronicGovernment.Infrastucture.Repositories;
using NUnit.Framework;

namespace ElectronicGovernment.Tests.Infrastructure.Repositories
{
    [TestFixture]
    internal class GovernmentRepositoryTest : RepositoryTestBase
    {
        [Test]
        public void After_creating_government_is_one_government_in_database()
        {
            var government = new Government();

            var governmentRepository = new GovernmentRepository();
            governmentRepository.Create(government);

            int governmentsCount = governmentRepository.CountGovernments();

            Assert.AreEqual(1, governmentsCount);
        }

        [Test]
        public void Can_create_government()
        {
            var government = new Government();

            var governmentRepository = new GovernmentRepository();
            var governmentCreated = governmentRepository.Create(government);

            Assert.NotNull(governmentCreated);
            Assert.GreaterOrEqual(governmentCreated.Id, 1);
        }

        [Test]
        public void Can_get_government_by_id()
        {
            var government = new Government();

            var governmentRepository = new GovernmentRepository();
            var createdGovernment = governmentRepository.Create(government);
            var fetchedGovernment = governmentRepository.GetGovernment(createdGovernment.Id);

            Assert.NotNull(fetchedGovernment);
            Assert.AreEqual(fetchedGovernment.Id, createdGovernment.Id);
        }
    }
}